package com.gzc.just.play.last.war.centralserver.inventory.repository;

import com.gzc.just.play.last.war.centralserver.inventory.model.ItemStack;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ItemStackRepository extends JpaRepository<ItemStack, Long> {
    
    List<ItemStack> findByInventoryId(Long inventoryId);
    
    List<ItemStack> findByInventoryIdAndItemId(Long inventoryId, Long itemId);
    
    @Query("SELECT SUM(is.quantity) FROM ItemStack is WHERE is.inventoryId = :inventoryId")
    Integer sumQuantitiesByInventoryId(@Param("inventoryId") Long inventoryId);
    
    @Query("SELECT SUM(is.quantity) FROM ItemStack is WHERE is.inventoryId = :inventoryId AND is.itemId = :itemId")
    Integer sumQuantitiesByInventoryIdAndItemId(@Param("inventoryId") Long inventoryId, @Param("itemId") Long itemId);
}
